package com.monise.dao.DAO;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;

import com.monise.dao.BaseDao.BaseDaoImpl;
import com.monise.model.ConsultaServico;
import com.monise.model.DadosConsulta;

public class ConsultaServicoDao extends BaseDaoImpl<ConsultaServico, Integer> {
	
	public List<ConsultaServico> getConsultasServico(DadosConsulta consulta) {

		EntityManagerFactory factory = Persistence
				.createEntityManagerFactory("pet");
		EntityManager manager = factory.createEntityManager();

		manager.getTransaction().begin();
		Query query = manager
				.createQuery("SELECT a from ConsultaServico a where a.consulta.pkDadosConsulta=:consulta");
		query.setParameter("consulta", consulta.getPkDadosConsulta());

		@SuppressWarnings("unchecked")
		List<ConsultaServico> consultas = query.getResultList();

		manager.getTransaction().commit();
		manager.close();

		return consultas;
	}
}
